//01背包
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int m,bagweight;
	cin >> m >> bagweight;
	vector<int> weight(m);
	vector<int> value(m);
	for(int i = 0; i < m; i++)
		cin >> weight[i];
	for(int i = 0; i < m; i++)
		cin >> value[i];
	
	vector<int> dp(bagweight+1);
	
	for(int i = weight[0]; i <= dp.size(); i++)
		dp[i] = value[0];
	
	for(int i = 1; i < m; i++)
	{
		for(int j = bagweight; j >=0; j--)
		{
			if(j < weight[i]) continue;
			else dp[j] = max(dp[j],dp[j-weight[i]] + value[i]);
		}
	}
	cout << dp[bagweight];
	return 0;
}
